package top.yuhaitao.cloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import top.yuhaitao.cloud.entity.User;

@RestController
public class MovieController2 {
	@Autowired
	private RestTemplate restTemplate;
	@Autowired
	private LoadBalancerClient loadBalancerClient;

	@RequestMapping("/getUserById2")
	public User getUserById2(Long id) {
		return restTemplate.getForObject("http://springboot-cloud-provider-user/getUserById?id=" + id, User.class);
	}

	@RequestMapping("/test")
	public void test(Long id) {
		ServiceInstance choose = loadBalancerClient.choose("springboot-cloud-provider-user");
		System.out.println(choose.getHost() + "-" + choose.getPort() + "-" + choose.getServiceId() + "-" + choose.getUri());

	}
}
